package com.wc.算法基础课.E第五讲动态规划.数位统计DP.求和;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/20 17:56
 * @description http://43.138.190.70:8888/p/LQ1028T
 */
public class Main {
    static int N = 110;
    static long[][] f = new long[N][10];
    static long[] base = new long[N];
    static int P = (int) 1e9 + 7;
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int[] nums = new int[N];
    static int n, x;

    static void init() {
        base[0] = 1;
        for (int i = 1; i < N; i++) {
            base[i] = base[i - 1] * 10 % P;
        }
        for (int i = 1; i < N; i++) {
            for (int j = 0; j < 10; j++) {
                if (j == 0 || j == 1 || j == 2 || j == 9) {
                    f[i][j] = base[i - 1];
                } else {
                    for (int k = 0; k < 10; k++) {
                        f[i][j] += f[i - 1][k] % P;
                    }
                }
            }
        }
    }

    public static void main(String[] args) {
        init();
        n = sc.nextInt();
        while (n-- > 0) {
            String x = sc.next();
            out.println(dp(x));
            out.flush();
        }
    }

    static long dp(String numStr) {
        if (numStr.equals("0")) return 1;
        char[] chs = numStr.toCharArray();
        int len = chs.length;
        for (int i = 1; i <= len; i++) {
            nums[len - i] = chs[i - 1] - '0';
        }
        long res = 0;
        int last = 0;
        for (int i = len - 1; i >= 0; i--) {
            int x = nums[i];
            for (int j = i == len - 1 ? 1 : 0; j < x; j++) {
                res = (res + f[i + 1][j]) % P;
            }
            // 当前字母是这4个当中的一个直接算后面的数就好
            if (x == 0 || x == 1 || x == 2 || x == 9) {
                long num = 0;
                for (int j = i - 1; j >= 0; j--) {
                    num = ((num * 10) + nums[j]) % P;
                }
                // 0 ~ 后面所有
                res = (res + num + 1) % P;
                break;
            }
        }

        // 处理前导零
        for (int i = 1; i < len; i++) {
            for (int j = 1; j <= 9; j++) {
                res = (res + f[i][j]) % P;
            }
        }
        return res;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
